package org.springframework.security.samples.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.security.samples.config.property.SpringRedisProperties;

@Configuration
@EnableConfigurationProperties({SpringRedisProperties.class})
@ConditionalOnProperty({"spring.redis.host", "spring.redis.port"})
public class RedisSimpleConfig {

    @Bean
    public LettuceConnectionFactory redisConnectionFactory(SpringRedisProperties redisProperties) {
        return new LettuceConnectionFactory(new RedisStandaloneConfiguration(redisProperties.getHost(), redisProperties.getPort()));
    }
}
